﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class player : MonoBehaviour
{
    // Start is called before the first frame update
    public Rigidbody2D rb ;
    Animator anim;
    public float jumpforce;
    public bool onground;
    bool isDead=false;
    public LayerMask ground;
    public float checkRadius;
    public GameObject groundCheck;
    void Start()
    {
        rb=GetComponent<Rigidbody2D>();
        anim=GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        onground=Physics2D.OverlapCircle(groundCheck.transform.position,checkRadius,ground);
        Movement();
    }
    void Movement(){
        anim.SetBool("onground",onground);
        if(Input.GetButtonDown("Jump")){
            if(onground)
                rb.velocity=new Vector2(rb.velocity.x,jumpforce);
        }
        transform.position= new Vector3(-4.5f,transform.position.y,0);
    }
    private void OnDrawGizmosSelected(){
        Gizmos.color=Color.blue;
        Gizmos.DrawWireSphere(groundCheck.transform.position,checkRadius);
    }
    void OnTriggerEnter2D(Collider2D other){
        if(other.gameObject.CompareTag("enemies")){
            anim.SetBool("isdead",true);
        }
            
    }
    public void PlayerDead(){
       isDead=true;
       GM.GameOver(isDead);
    }
}
